package com.ssm.controller;

import com.hqj.HightChartUtil;
import com.ssm.entity.Down;
import com.ssm.entity.Files;
import com.ssm.service.DownServiceI;
import com.ssm.service.FilesServiceI;
import com.ssm.service.HighchartServiceI;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Calendar;
import java.util.Date;
import java.util.Map;

@RequestMapping("/hc")
@Controller
public class HomeController extends BaseController {

    @Resource(name="filesServiceI")
    private FilesServiceI fsi;
    @Resource(name = "downServiceI")
    private DownServiceI dsi;
    @Resource(name = "highchartServiceI")
    private HighchartServiceI hsi;


    @RequestMapping("/calcUpload")
    @ResponseBody
    public int calcUpload(Files f){
        if("m3".equals(f.getFilePath())){
            Calendar c = Calendar.getInstance();
            c.set(c.get(1),c.get(2),c.get(5),0,0,0);
            f.setStartTime(c.getTime());
            c.set(c.get(1),c.get(2),c.get(5),23,59,59);
            f.setEndTime(c.getTime());
        }
        return fsi.find(f).size();
    }

    @RequestMapping("/calcDownload")
    @ResponseBody
    public int calcDownload(Down d){
        if("m4".equals(d.getStatus())){
            Calendar c = Calendar.getInstance();
            c.set(c.get(1),c.get(2),c.get(5),0,0,0);
            d.setStartTime(c.getTime());
            c.set(c.get(1),c.get(2),c.get(5),23,59,59);
            d.setEndTime(c.getTime());
        }
        return dsi.find(d).size();
    }


    @RequestMapping("/addDown/{id}")
    @ResponseBody
    public Map<String,Object> addDown(@PathVariable(value = "id") int id){
        //保存下载记录
        Down d = new Down();
        d.setDownTime(new Date());
        d.setDownUser("");
        d.setFileId(id);
        Map<String,Object> map = dsi.add(d);
        return map;
    }

    @RequestMapping("/pie")
    @ResponseBody
    public String getPie(){
        String str = hsi.getPie();
        return str;
    }

    @RequestMapping("/blc")
    @ResponseBody
    public String getBLC(){
        String str = hsi.getBLC();
        return str;
    }

}
